package com.hcrazy.manchester.app.controllers;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.hcrazy.manchester.app.pojo.Coupon;
import com.hcrazy.manchester.app.pojo.LiveAddress;
import com.hcrazy.manchester.app.pojo.Rent;
import com.hcrazy.manchester.app.pojo.Secondary;
import com.hcrazy.manchester.app.pojo.Topic;
import com.hcrazy.manchester.app.services.CouponService;
import com.hcrazy.manchester.app.services.LiveAddressService;
import com.hcrazy.manchester.app.services.RentService;
import com.hcrazy.manchester.app.services.SecondaryService;
import com.hcrazy.manchester.app.services.TopicService;
import com.hcrazy.manchester.app.utils.Constant;
import com.hcrazy.manchester.app.utils.Log;

@Controller
@RequestMapping("/")
public class FrontController {
	
	@Autowired
	private TopicService topicService;
	
	@Autowired
	private LiveAddressService liveAddressService;

	@Autowired
	private CouponService couponService;
	
	@Autowired
	private SecondaryService secondaryService;
	
	@Autowired
	private RentService rentService;
	
	@RequestMapping("index")
	public void index(Model model){
		try {
			//获取论坛热帖
			List<Topic> topics = topicService.getHotTopics(5);
			model.addAttribute("topics", topics);
			
			//我是吃货：商户列表
			List<LiveAddress> foodInfos = liveAddressService.getAddressInfos(Constant.LIVE_SORT_ID_FOOD, 7);
			model.addAttribute("foodInfos", foodInfos);
			
			//优惠券
			List<Coupon> coupons = couponService.getAllCoupons(7);
			model.addAttribute("coupons", coupons);
			
			//住在曼城
			List<Rent> rents = rentService.getRents(7);
			model.addAttribute("rents", rents);
			
			//二手
			List<Secondary> secondaries = secondaryService.getSecondaries(7);
			model.addAttribute("secondaries", secondaries);
			
		} catch (Exception e) {
			Log.error(e.getMessage(), e);
		}
	}
	
	@RequestMapping("front/register")
	public void register(){
		
	}
}
